package com.lizhi.yun.core.handler;

import com.lizhi.common.yun.entity.ListResponseResult;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.db.jlc.dao.JlcTreatrecordDao;
import com.lizhi.yun.db.jlc.pojo.JlcTreatrecordPOJO;
import com.lizhi.mybatis.interceptor.PageBounds;
import com.lizhi.utils.StringUtils;
import com.lizhi.yun.deploy.NewBaseHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: lizhi
 * @Description:
 * @Date: create in 2020/11/4 9:32
 */
@Slf4j
@Service
public class ServiceJlcTreatrecordHandlerNew extends NewBaseHandler {

    @Resource
    private JlcTreatrecordDao jlcTreatrecordDao;

    /**
     * 分页查询
     * @param json
     * @return
     */
    public ListResponseResult doMain(String json){
        Map<String, Object> map = SamJsonUtil.toMap(json);
        PageBounds pageBounds = getPageBounds(map);
        List<JlcTreatrecordPOJO> list = jlcTreatrecordDao.selectByMap(map, pageBounds);
        return getListResult(pageBounds.getCountRows(), list, map);
    }

    public ListResponseResult doMain(Map<String, Object> map){
        PageBounds pageBounds = getPageBounds(map);
        List<JlcTreatrecordPOJO> list = jlcTreatrecordDao.selectByMap(map, pageBounds);
        return getListResult(pageBounds.getCountRows(), list, map);
    }

    /**
     * 根据id查询信息
     * @param id
     * @param hospitalid
     * @param hospitalsystemid
     * @return
     */
    public ListResponseResult selectById(String id, String hospitalid, String hospitalsystemid){
        JlcTreatrecordPOJO jlcTreatrecordPOJO = jlcTreatrecordDao.selectById(id, hospitalid, hospitalsystemid);
        if (StringUtils.isEmpty(jlcTreatrecordPOJO)){
            return getListResult("未查询到患者信息", false);
        }
        return getListResult(jlcTreatrecordPOJO);
    }
}
